package com.ttctracker;


import com.ttctracker.favorite.Favorite;
import com.ttctracker.map.Map;
import com.ttctracker.search.Search;
import com.ttctracker.util.MyApp;

import android.app.ActivityGroup;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;

public class Main extends ActivityGroup {
	private static TabHost myTabHost=null;
	private MyApp myApp;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Resources res = getResources();
       // myApp=(MyApp)getApplication();
        myTabHost = (TabHost) findViewById(R.id.ttc_tracker_tabhost); // The activity TabHost
		TabHost.TabSpec spec; // Resusable TabSpec for each tab
		Intent intent; // Reusable Intent for each tab
		myTabHost.setup(this.getLocalActivityManager());
		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, Search.class);

		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = myTabHost.newTabSpec("search")
				.setIndicator("Search", res.getDrawable(R.drawable.ic_tab_ic_tab_route_search))
				.setContent(intent);
		myTabHost.addTab(spec);
		
		// Do the same for the other tabs
		intent = new Intent().setClass(this, Favorite.class);
		spec = myTabHost.newTabSpec("favorite")
				.setIndicator("Favorite", res.getDrawable(R.drawable.ic_tab_ic_tab_route_favorite))
				.setContent(intent);
		myTabHost.addTab(spec);

		intent = new Intent().setClass(this, Map.class);
		spec = myTabHost.newTabSpec("map")
				.setIndicator("Map", res.getDrawable(R.drawable.ic_tab_ic_tab_route_map))
				.setContent(intent);
		myTabHost.addTab(spec);
		
		setupUI();
		//myApp.popKeyBoard(Main.this);
    }
    
    private void setupUI() {
        RadioButton tabSearch = (RadioButton) findViewById(R.id.tab_head_search);
        RadioButton tabFav = (RadioButton) findViewById(R.id.tab_head_fav);
        RadioButton tabMap = (RadioButton) findViewById(R.id.tab_head_map);
        
        /*tabSearch.setButtonDrawable(R.drawable.ic_tab_ic_tab_route_search_selected);
        tabFav.setButtonDrawable(R.drawable.ic_tab_ic_tab_route_favorite_selected);
        tabMap.setButtonDrawable(R.drawable.ic_tab_ic_tab_route_map_selected);*/
        
        RadioGroup rg = (RadioGroup) findViewById(R.id.tabHeads);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup group, final int checkedId) {
                switch (checkedId) {
                case R.id.tab_head_search:
                    myTabHost.setCurrentTab(0);
                    break;
                case R.id.tab_head_fav:
                	myTabHost.setCurrentTab(1);
                    break;
                case R.id.tab_head_map:
                	myTabHost.setCurrentTab(2);
                    break;
                
                }
            }
        });
    }
    
    
}